package com.ustb.service;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.ustb.util.MultiChainUtil;

public class TransactionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String address=request.getParameter("address");
        String amount=request.getParameter("amount");
        String asset = "asset1";
        String messdate = "null";
        try{
            String myaddress = MultiChainUtil.getAllAddress().get(0).toString();
            MultiChainUtil.sendWithDataFrom(myaddress,address,asset,Integer.parseInt(amount),messdate);
        }catch (Exception e){
            e.printStackTrace();
            response.sendRedirect("detail.jsp?error=1");
            return;
        }
        System.out.println();
        response.sendRedirect("detail.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
